package tech.aistar.mapper;

import org.apache.ibatis.annotations.*;
import tech.aistar.pojo.ShoppingCart;

import java.util.List;

@Mapper
public interface CartMapper {
    //根据user_id查询      用子查询
    ShoppingCart findByUserId(int user_id);

    //根据user_id和flower_id查询
    @Select("select count from shopping_cart where user_id=#{user_id} and flower_id=#{flower_id}")
    Integer findByUserIdAndFlowerId(int user_id, int flower_id);

    //删除  根据user_id和flower_id
    @Delete("delete from shopping_cart where user_id = #{user_id} and flower_id = #{flower_id}")
    int deleteByUserIdAndFlowerId(int user_id,int flower_id);

    //删除多条  根据user_id和flower_id
    @Delete("delete from shopping_cart where user_id = #{user_id} and flower_id in ${ids}")
    int deleteByUserIdAndFlowerIds(int user_id,String ids);

    //添加
    @Insert("insert into shopping_cart(user_id,flower_id,count) values(#{userId},#{flowerId},#{count})")
    int insert(int userId,int flowerId,int count);

    //修改商品数量   根据user_id和flower_id
    @Update("update shopping_cart set count = #{count} where user_id = #{userId} and flower_id = #{flowerId}")
    int updateCount(int userId,int flowerId,int count);


    @Select("select flower_id from shopping_cart where user_id = #{user_id}")
    List<Integer> getFlowerIdsByUserId(int user_id);

    @Select("select count from shopping_cart where user_id = #{user_id}")
    List<Integer> getFlowerCountsByUserId(int user_id);

}
